//
// Created by darcy on 4/30/21.
//

#include "../Include/CheckingAccount.h"
#include <iostream>

using namespace std;

CheckingAccount::CheckingAccount(double b, double s) : Account(b) {
    transactionFee = s;
}

void CheckingAccount::credit(double m) {
    Account::credit(m);
    if (Account::getBalance() >= transactionFee)
        Account::debit(transactionFee);
    else {
        cout << "Transaction fee exceeded account balance while crediting"
             << endl;
        Account::debit(m);
    }
}

bool CheckingAccount::debit(double m) {
    if (Account::debit(m)) {
        if (transactionFee <= getBalance()) {
            Account::debit(transactionFee);
            return true;
        } else {
            Account::credit(m);
            cout << "Transaction fee exceeded account balance while debiting"
                 << endl;
            return false;
        }
    } else
        return false;
}
